﻿using System;
using System.Data;
using l1cs.server.model.Instance;
using l1cs.server.utils;
using l1cs.server.model.poison;

namespace l1cs.server.model.trap
{
    class L1PoisonTrap : L1Trap
    {
        private readonly String _type;
        private readonly int _delay;
        private readonly int _time;
        private readonly int _damage;

        public L1PoisonTrap( DataRow item )
            : base( item )
        {
            _type = Convert.ToString( item["poisonType"] );
            _delay = SqlUtils.toInt( item["poisonDelay"] );
            _time = SqlUtils.toInt( item["poisonTime"] );
            _damage = SqlUtils.toInt( item["poisonDamage"] );
        }

        override
        public void onTrod( L1PcInstance trodFrom, L1Object trapObj )
        {
            sendEffect( trapObj );

            if ( _type.Equals( "d" ) )
            {
                L1DamagePoison.doInfection( trodFrom, trodFrom, _time, _damage );
            }
            else if ( _type.Equals( "s" ) )
            {
                L1SilencePoison.doInfection( trodFrom );
            }
            else if ( _type.Equals( "p" ) )
            {
                L1ParalysisPoison.doInfection( trodFrom, _delay, _time );
            }
        }
    }
}
